package com.libc.yygh.common.config;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.service.Contact;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;

@Configuration
// @EnableSwagger2
// @ConfigurationProperties (prefix = "swagger2")
public class Swagger2Config
{
    //api接口包扫描路径
    public static final String SWAGGER_SCAN_BASE_PACKAGE = "com.libc.yygh";
    public static final String VERSION = "3.1.0";

    @Value ("${swagger2.scanPackage}")
    private String scanPackage;
    @Value ("${swagger2.title}")
    private String title;
    @Value ("${swagger2.version}")
    private String version;
    @Value ("${swagger2.description}")
    private String description;
    @Value ("${swagger2.termsOfServiceUrl}")
    private String termsOfServiceUrl;
    @Value ("${swagger2.groupName}")
    private String groupName;
    @Value ("${swagger2.name}")
    private String name;
    @Value ("${swagger2.url}")
    private String url;
    @Value ("${swagger2.email}")
    private String email;

    @Bean
    public Docket createRestApi( )
    {
        // return new Docket(DocumentationType.SWAGGER_2)
        //         .groupName(groupName)
        //         .apiInfo(apiInfo())
        //         .select()
        //         //  //指向自己的controller即可
        //         .apis(RequestHandlerSelectors.basePackage(scanPackage))
        //         //  可以根据url路径设置哪些请求加入文档，忽略哪些请求
        //         .paths(PathSelectors.any())
        //         .build();
        return new Docket(DocumentationType.SPRING_WEB)
                .apiInfo(apiInfo())
                .select()
                .apis(RequestHandlerSelectors.basePackage(scanPackage))
                .paths(PathSelectors.any()) // 可以根据url路径设置哪些请求加入文档，忽略哪些请求
                .build();
    }

    /************************************************************* <br>
     *
     *说明:  构建api文档的详细信息函数<br>
     *
     * @Description   <br>
     * @Date Created on 2022/4/6  10:21  <br>
     * @return springfox.documentation.service.ApiInfo  <br>
     * @Author LIBENCHENG
     * @version 1.0 <br>
     ************************************************************* <br>
     */
    private ApiInfo apiInfo( )
    {
        // return new ApiInfoBuilder()
        //         //页面标题
        //         .title(title)
        //         // 创建人信息  可以为null
        //         .contact(new Contact(name, url, email))
        //         // 版本号
        //         .version(version)
        //         // 描述
        //         .description(description)
        //         .termsOfServiceUrl(termsOfServiceUrl)
        //         .build();
        return new ApiInfoBuilder()
                //设置文档的标题
                .title("熙软科技人力管理系统")
                // 设置文档的描述
                .description("熙软科技人力管理系统 API 接口文档")
                // 设置文档的版本信息-> 1.0.0 Version information
                .version(VERSION)
                // 设置文档的License信息->1.3 License information
                .contact(new Contact("xisofttec", "https://www.xisofttec.com/", "550583975@qq.com"))
                .build();
    }

    public String getScanPackage( ) { return scanPackage; }

    public void setScanPackage(String scanPackage) { this.scanPackage = scanPackage; }

    public String getTitle( ) { return title; }

    public void setTitle(String title) { this.title = title; }

    public String getVersion( ) { return version; }

    public void setVersion(String version) { this.version = version; }

    public String getDescription( ) { return description; }

    public void setDescription(String description) { this.description = description; }

    public String getTermsOfServiceUrl( ) { return termsOfServiceUrl; }

    public void setTermsOfServiceUrl(String termsOfServiceUrl) { this.termsOfServiceUrl = termsOfServiceUrl; }

    public String getGroupName( ) { return groupName; }

    public void setGroupName(String groupName) { this.groupName = groupName; }

    public String getName( ) { return name; }

    public void setName(String name) { this.name = name; }

    public String getUrl( ) { return url; }

    public void setUrl(String url) { this.url = url; }

    public String getEmail( ) { return email; }

    public void setEmail(String email) { this.email = email; }
}   